package com.sopaths.crawler.task.handler;

import javax.inject.Inject;
import javax.inject.Named;

import org.apache.log4j.Logger;

import com.sopaths.contract.domain.Recruitment;
import com.sopaths.contract.service.RecruitmentService;
import com.sopaths.crawler.tasks.CrawlerTask;
import com.sopaths.crawler.tasks.RecruitmentCrawlerTask;

@Named
public class RecruitmentCrawlerTaskResultHandler implements CrawlerTaskResultHandler {

	private final Logger logger = Logger.getLogger(RecruitmentCrawlerTaskResultHandler.class);

	@Inject
	private RecruitmentService recruitmentService;

	@Override
	public void handle(CrawlerTask<?> task) {
		RecruitmentCrawlerTask innerTask = (RecruitmentCrawlerTask) task;
		try {
			Recruitment recruitment = innerTask.getResult();
//			recruitmentService.create(recruitment);
			recruitmentService.saveCrawledRecruitment(recruitment);
		} catch (Exception ex) {
			logger.error("An error occurred while handling task result. Task: " + task, ex);
		}
	}

}
